home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
lxml
/
builder.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
3KB
|
115 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import lxml.etree as ET
try:
from functools import partial
except ImportError:
def partial(func, tag):
return (lambda : func(tag, *args, **kwargs))
try:
callable
except NameError:
def callable(f):
return hasattr(f, '__call__')
try:
basestring = __builtins__['basestring']
except (NameError, KeyError):
basestring = str
try:
unicode = __builtins__['unicode']
except (NameError, KeyError):
unicode = str
class ElementMaker(object):
def __init__(self, typemap = None, namespace = None, nsmap = None, makeelement = None):
if namespace is not None:
self._namespace = '{' + namespace + '}'
else:
self._namespace = None
if nsmap:
self._nsmap = dict(nsmap)
else:
self._nsmap = None
if makeelement is not None:
self._makeelement = makeelement
else:
self._makeelement = ET.Element
if typemap:
typemap = typemap.copy()
else:
typemap = { }
def add_text(elem, item):
elem.text = None if len(elem) else '' + item
if str not in typemap:
typemap[str] = add_text
if unicode not in typemap:
typemap[unicode] = add_text
def add_dict(elem, item):
attrib = elem.attrib
for k, v in item.items():
if isinstance(v, basestring):
attrib[k] = v
continue
attrib[k] = typemap[type(v)](None, v)
if dict not in typemap:
typemap[dict] = add_dict
self._typemap = typemap
def __call__(self, tag, *children, **attrib):
get = self._typemap.get
if self._namespace is not None and tag[0] != '{':
tag = self._namespace + tag
elem = self._makeelement(tag, nsmap = self._nsmap)
if attrib:
get(dict)(elem, attrib)
for item in children:
if callable(item):
item = item()
t = get(type(item))
if t is None:
if ET.iselement(item):
elem.append(item)
continue
raise TypeError('bad argument type: %r' % item)
continue
v = t(elem, item)
if v:
get(type(v))(elem, v)
continue
return elem
def __getattr__(self, tag):
return partial(self, tag)
E = ElementMaker()